<?php
	class Album extends CI_Model
	{
		public function __construct()
		{
			$this->load->database();
		}
		
		public function get_all_album()
		{
			$query = $this->db->query("SELECT al.AlbumId, g.Name Genre, ar.Name Artist, al.Title, al.Price
				FROM albums al, artists ar, genres g
				WHERE al.ArtistId = ar.ArtistId
				AND al.GenreId = g.GenreId");
			return $query->result();
		}
		
		public function get_album_by_id($id)
		{
			$query = $this->db->query(
					"SELECT al.AlbumId, g.Name Genre, ar.Name Artist, al.Title, al.Price,al.AlbumArtUrl
					FROM albums al
					INNER JOIN artists ar 
					ON al.ArtistId = ar.ArtistId
					JOIN genres g 
					ON al.GenreId = g.GenreId
					WHERE al.AlbumId =$id");
			return $query->row();
		}

		public function set_album($data)
		{			
			return $this->db->insert('albums',$data);
		}
		
		public function update_album($id,$data)
		{			
			$this->db->where('AlbumId',$id);
			$this->db->update('albums',$data);
		}
		
		public function delete_album($id)
		{
			$this->db->where('AlbumId',$id);
			$this->db->delete('albums');
		}
		
		public function get_album_title_by_id($id)
		{
			$this->db->select('Title');
			$this->db->where('AlbumId',$id);
			$query = $this->db->get('albums');
			
			return $query->row();
		}
	}
?>